package com.stock.demo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.stock.demo.adapter.viewholder.StockViewHolder;

import java.util.ArrayList;

/**
 * Created by XuZhaoyu on 2017/7/1.
 */

public abstract class StockBaseAdapter<T> extends RecyclerView.Adapter<StockViewHolder> {

    private Context mContext;
    private ArrayList<T> mData;

    public StockBaseAdapter(Context context, ArrayList<T> data) {
        mContext = context;
        mData = data;
    }

    public abstract int setLayoutResId();

    public T getItem(int position) {
        if (mData.size() <= position) {
            return null;
        }
        return mData.get(position);
    }

    @Override
    public StockViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(setLayoutResId(), parent, false);
        return new StockViewHolder(view);
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

}
